#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Copyright (c) 2008 Andrew Coleman under the MIT License
# See COPYING at the root directory of this project.
#-------------------------------------------------------------------------------
# Standard Modules
import sys
# Project Modules
import conf

################################################################################
# Set up first-run stuff
OutputModes = {
    "quiet": 0,
    "critical": 20,
    "error": 40,
    "warning": 60,
    "info": 80,
    "debug": 100
}
MessageLevels = ("critical", "error", "warning", "info", "debug")
OutputQueue = list()

################################################################################
class Message:
    """A generic outputtable message, usually used for info, debugging, or warning the user"""
    #----------------------------------------------------------------------
    def __init__(self, MessageText, MessageLevel):
        """Constructor"""
        self.Level = MessageLevel
        self.Str = MessageText

    def __str__(self):
        return self.Str

def Push(MessageText, MessageLevel="info"):
    if MessageLevel not in MessageLevels:
        MessageLevel = "info"
    OutputQueue.append(Message(MessageText, MessageLevel))


def Loop():
    if conf.OutputMode == "quiet":
        OutputQueue = list()
        return

    while True:
        try:
            OutputMessage = OutputQueue.pop(0)
            if OutputModes[conf.OutputMode] > OutputModes[OutputMessage.Level]:
                if OutputModes[conf.OutputMode] < 80:
                    print >> sys.stderr, OutputMessage.Level + "> " + OutputMessage
                else:
                    print OutputMessage.Level + "> " + OutputMessage
        except IndexError, e:
            print e
            return

Push("Entering '" + conf.OutputMode + "' mode (" + str(OutputModes[conf.OutputMode]) + ")")